import matplotlib.pyplot as plt
import numpy as np
import torch
import math
def f(x):
    return 3*x**2 + 4*x

def g(x):
    return math.sin(x)
# plt.ion()

x = np.arange(0,3,0.1)
y = [f(i) for i in x]
g = [g(i) for i in x]
y1 = [10*i-3 for i in x]
g1 = [math.cos(1)*i+math.sin(1)-math.cos(1) for i in x]
plt.subplot(211)
plt.plot(x,y,"#66ccff",label=1)
plt.plot(x,y1,"red",linestyle="--",label=2)
plt.legend(["f(x)","Tangent line"])
plt.title("Test")
plt.xlabel("zheshiX")
plt.ylabel("zheshiY")
plt.subplot(212)
# plt.ylim(-1,1)
plt.plot(x,g,"#66ccff",label=1)
plt.plot(x,g1,"red",linestyle="--",label=2)
plt.legend(["g(x)","Tangent line"])
plt.title("Test1")
plt.xlabel("zheshiX")
plt.ylabel("zheshiY")
plt.tight_layout() # 防止标题重叠
plt.show()
# help(plt.plot)